package com.chaodows.commons.util;

import com.chaodows.commons.dto.result.ResultCode;
import com.chaodows.commons.exception.BusinessException;

/**
 * ============================
 *
 * @Author pengzhichao
 * @Description //TUDO $
 * @Date 2021/7/26 19:04
 * @Version 1.0
 * ============================
 **/
public class AssertBusinessUtil {

    private AssertBusinessUtil(){}

    public static void isTrue(boolean expression,String message){
        if(!expression){
            throw new BusinessException(message);
        }
    }

    public static void isFalse(boolean expression,String message){
        if(expression){
            throw new BusinessException(message);
        }
    }

    /**
     *
     * @param expression
     * @param title
     * @param message
     */
    public static void isTrue(boolean expression,String title,String message){
        if(!expression){
            throw new BusinessException(title,message);
        }
    }

    /**
     *
     * @param expression
     * @param title
     * @param message
     */
    public static void isFalse(boolean expression,String title,String message){
        if(expression){
            throw new BusinessException(title,message);
        }
    }

    /**
     * 设置title
     * @param expression
     * @param resultCode
     */
    public static void isTrue(boolean expression, ResultCode resultCode){
        if(!expression){
            throw new BusinessException(resultCode);
        }
    }

    /**
     * 设置返回码
     * @param expression
     * @param resultCode
     */
    public static void isFalse(boolean expression,ResultCode resultCode){
        if(expression){
            throw new BusinessException(resultCode);
        }
    }

    /**
     * 默认抛异常
     * @param expression 为true
     */
    public static void isTrue(boolean expression){
          if(!expression){
              throw new BusinessException("[Assertion failed] - this expression must be true");
          }
    }
    /**
     * 默认抛异常
     * @param expression 为false
     */
    public static void isFalse(boolean expression){
        if(expression){
            throw new BusinessException("[Assertion failed] - this expression must be false");
        }
    }
}
